package com.example.service;

import com.example.dto.BorrowRecordDTO;
import com.example.mapper.BorrowMapper;
import com.example.mapper.BorrowRecordMapper;
import com.example.pojo.Borrow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BorrowServicelmpl implements BorrowService {

    @Autowired
    private BorrowMapper borrowMapper;

    @Autowired
    private BorrowRecordMapper borrowRecordMapper;

    //
    @Override
    public List<BorrowRecordDTO> getAllBorrows() {
        return borrowRecordMapper.getAllBorrowRecords();
    }

    //修改还书状态
    @Override
    public boolean updateBorrowStatus(Integer id, String returnDate) {
        return borrowMapper.updateStatus(id, returnDate);
    }

    @Override
    //新增借书状态
    public boolean insertBorrow(Borrow borrow) {
        return borrowMapper.insertBorrow(borrow);
    }


    // 查询分页数据（带模糊搜索）
    @Override
    public List<BorrowRecordDTO> searchBorrows(String keyword, int offset, int pageSize) {
        return borrowMapper.searchBorrows(keyword, offset, pageSize);
    }

    // 查询总数量
    @Override
    public int countBorrows(String keyword) {
        return borrowMapper.countBorrows(keyword);
    }
}